package training.osms.view.category;

import javax.faces.bean.ManagedBean;
import javax.faces.context.FacesContext;

import training.osms.controller.category.CategoryController;
import training.osms.model.category.Category;
import training.osms.view.OsmsUtil;

@ManagedBean
public class NewCategoryForm {

	
	private CategoryForm form;
	private boolean catSaved;
	
	public NewCategoryForm(){
		this.form = new CategoryForm();
	}

	
	
	public void insertNewCategory(){
		
		CategoryController controller = new CategoryController();
		controller.saveCategory(this.form.getCategory());
		catSaved = true;
		OsmsUtil.sendMessage("Category saved.", OsmsUtil.INFO);
		this.form.setCategory(new Category());
	}
	
	public boolean getHaveMessages(){
		FacesContext context = FacesContext.getCurrentInstance();
		
		return context.getMessageList().size() > 0;
	}

	public boolean getCatSaved() {
		return catSaved;
	}

	public void setCatSaved(boolean catSaved) {
		this.catSaved = catSaved;
	}

	public CategoryForm getForm() {
		return form;
	}

	public void setForm(CategoryForm form) {
		this.form = form;
	}
	
}
